package com.springframework.beans;

import org.springframework.beans.*;
import org.springframework.lang.Nullable;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @Author 虎哥
 * @Description //TODO
 * 要带着问题去学习,多猜想多验证
 **/
public abstract class MyAbstractPropertyAccessor extends AbstractPropertyAccessor {

    void setPropertyValues(MyPropertyValues pvs) throws BeansException {
        this.setPropertyValues(pvs, false, false);
    }
    public void setPropertyValue2(MyPropertyValue pv) throws BeansException {
        this.setPropertyValue2(pv.getName(), pv.getValue());
    }

    public abstract void setPropertyValue2(String propertyName, @Nullable Object value) throws BeansException;

    public void setPropertyValues(MyPropertyValues pvs, boolean ignoreUnknown, boolean ignoreInvalid) throws BeansException {
        List<PropertyAccessException> propertyAccessExceptions = null;
        List<MyPropertyValue> propertyValues = pvs instanceof MyMutablePropertyValues ? ((MyMutablePropertyValues)pvs).getPropertyValueList() : Arrays.asList(pvs.getPropertyValues());
        Iterator var6 = propertyValues.iterator();

        while(var6.hasNext()) {
            MyPropertyValue pv = (MyPropertyValue)var6.next();

            try {
                this.setPropertyValue2(pv);
            } catch (NotWritablePropertyException var9) {
                if (!ignoreUnknown) {
                    throw var9;
                }
            } catch (NullValueInNestedPathException var10) {
                if (!ignoreInvalid) {
                    throw var10;
                }
            } catch (PropertyAccessException var11) {
                if (propertyAccessExceptions == null) {
                    propertyAccessExceptions = new ArrayList();
                }

                propertyAccessExceptions.add(var11);
            }
        }

        if (propertyAccessExceptions != null) {
            PropertyAccessException[] paeArray = propertyAccessExceptions.toArray(new PropertyAccessException[0]);
            throw new PropertyBatchUpdateException(paeArray);
        }
    }
}
